package com.cskaoyan.service;

import com.cskaoyan.bean.MarketGoodsProduct;
import com.cskaoyan.bean.MarketGoodsProductExample;
import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.cskaoyan.util.TransactionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月29日 20:59
 */
public class GoodsProductServiceimpl implements GoodsProductService {
    @Override
    public void update(Integer goodsId, Short number, String specifications) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsProductMapper mapper = sqlSession.getMapper(MarketGoodsProductMapper.class);
        //这里开摆了，不根据具体参数弄了用他现成的
        mapper.addStock(goodsId, number);
    }

    @Override
    public void updateByShip(Integer goodsId, Short number, String specifications) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsProductMapper mapper = sqlSession.getMapper(MarketGoodsProductMapper.class);
        mapper.subStock(goodsId, number);
    }

    @Override
    public void add(MarketGoodsProduct product) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsProductMapper mapper = sqlSession.getMapper(MarketGoodsProductMapper.class);
        mapper.insertSelective(product);
    }

    @Override
    public List<MarketGoodsProduct> selectByGoodsId(Integer id) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsProductMapper mapper = sqlSession.getMapper(MarketGoodsProductMapper.class);
        MarketGoodsProductExample example = new MarketGoodsProductExample();
        MarketGoodsProductExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(id);
        List<MarketGoodsProduct> marketGoodsProducts = mapper.selectByExample(example);
        return marketGoodsProducts;

    }

    @Override
    public void updateByObject(MarketGoodsProduct product) {
        SqlSession sqlSession = TransactionUtil.getSqlSession();
        MarketGoodsProductMapper mapper = sqlSession.getMapper(MarketGoodsProductMapper.class);
        mapper.updateByPrimaryKeySelective(product);
    }
}
